/**
 *
 */
package picounit.ruby;

import org.apache.bsf.BSFException;
import org.apache.bsf.BSFManager;

import picounit.ruby.exception.InvalidScript;

public class RubyScriptExecutor {
    public RubyScriptExecutor(BSFManager manager) {
        this.manager = manager;
    }

    public void exec(String scriptFile) {
        String script = fileUtil.fileContents(scriptFile);

        try {
            manager.exec("ruby", scriptFile, -1, -1, script);
        }
        catch (BSFException bsfException) {
            throw new InvalidScript(scriptFile, script, bsfException);
        }
    }

    private final BSFManager manager;

    private final FileUtil fileUtil = new FileUtil();
}